'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:TaskTaskdetailCtrl
 * @description
 * # TaskTaskdetailCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('TaskTaskdetailCtrl', function(openApi, localStorageService, DataService, $location, Util, $routeParams) {
        var vm = this;
        this.curtab = 1
        this.commentList = [{
            value: "评论",
            key: "1"
        }, {
            value: "历史动态",
            key: "2"
        }];
        this.submenuhandle = function(key) {
            if (this.curtab == key) {
                return
            }
            this.curtab = key;
        }
        vm.getDetail = function() {
            var param = {}
            param.pkId = $routeParams.pkId;
            DataService.getData(openApi.worktaskDetail, param).then(function(data) {
                console.log(data)
                if (data) {
                    vm.data = data;
                } else {
                    Util.Toast("当前任务已不在", { callback: Util.goBack });
                }

            })
        };
        vm.setcomment = function() {
            localStorageService.set("taskdetail", vm.data)
        };
        vm.changestatus = function() {
            var param = {}
            param.pkId = $routeParams.pkId;
            DataService.getData(openApi.setTaskStatus, param).then(function(data) {
                Util.Toast(data);
                vm.getDetail()
            })
        };
        this.confirmchange = function() {
            var status = vm.data.status == 2 ? "未完成" : "已完成";
            var tip = '是否将任务标记为' + status;
                navigator.notification.confirm(
                    tip,
                    vm.changestatus,
                    "提示", ['确定', '取消']
                )
        }
        this.setting = function() {
            localStorageService.set("taskdetail", vm.data)
            $location.path("task/tasksetting");
        };
        this.addComment = function() {
            $location.path("task/addcomment/" + $routeParams.pkId);
        }
        this.init = function() {
            vm.getDetail()
        };
        this.init();
    });
